package org.reborn.model.bound

import org.reborn.math._
import scala.collection.mutable.ArrayBuffer

/**
 * A bounding volume that is made up of 4 planes that all intersect at
 * a single point and are also at right angles to each other. The planes
 * all point outward.
 * 
 * This bound is recommended only for view-frustum culling as the intersection
 * tests are not guaranteed to be 100% correct (it might produce false positives).
 * It is however guaranteed not to produce false negatives. Meaning that a bound 
 * intersection test will never return false if there is an actual intersection.
 */
class InfiniteFrustum(val start:VectorF, 
		val upperLeft:VectorF, val upperRight:VectorF, 
		val lowerLeft:VectorF, val lowerRight:VectorF) extends ConvexPlaneBound{

  lazy val edges:Seq[Line3F] = calcEdges

  lazy val leftPlane = Plane3F(start, (upperLeft-start) cross (lowerLeft-start))
  lazy val rightPlane = Plane3F(start, (lowerRight-start) cross (upperRight-start))
  lazy val bottomPlane = Plane3F(start, (lowerLeft-start) cross (lowerRight-start))
  lazy val topPlane = Plane3F(start, (upperRight-start) cross (upperLeft-start))
  
  lazy val planes:Seq[Plane3F] = calcPlanes
  
  
  private def calcEdges:Seq[Line3F] = {
	Array[Line3F](
			new Line3F(start, upperLeft),
			new Line3F(start, upperRight),
			new Line3F(start, lowerLeft),
			new Line3F(start, lowerRight))
  }
  
  private def calcPlanes:Seq[Plane3F] = {
	Array[Plane3F](leftPlane,topPlane,rightPlane,bottomPlane)
  }
}